package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品相关功能
 *
 * @Author itcast
 * @Create 2023/3/7
 **/
@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 添加菜品
     * @param dishDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加菜品")
    public Result addDish(@RequestBody DishDTO dishDTO){

        dishService.addDish(dishDTO);

        return Result.success();
    }

    /**
     * 菜品分页条件查询
     * @return
     */
    @ApiOperation("菜品分页条件查询")
    @GetMapping("/page")
    public Result dishPageList(DishPageQueryDTO dishPageQueryDTO){

        PageResult pageResult= dishService.dishPageList(dishPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 删除菜品
     * @return
     */
    @ApiOperation("删除菜品")
    @DeleteMapping
    public Result deleteDish(@RequestParam List<Integer> ids){
        dishService.deleteDish(ids);

        return Result.success();
    }

    /**
     * 根据id查询菜品
     * @return
     */
    @ApiOperation("根据id查询菜品")
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        DishVO dishVO= dishService.findById(id);

        return Result.success(dishVO);
    }

    /**
     * 根据分类查询菜品
     * @return
     */
    @ApiOperation("根据分类查询菜品")
    @GetMapping("/list")
    public Result findByCategoryId(Long categoryId){
        List<DishVO> dishVOS= dishService.findByCategoryId(categoryId);

        return Result.success(dishVOS);
    }

    /**
     * 修改菜品
     * @return
     */
    @ApiOperation("修改菜品")
    @PutMapping
    public Result updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDish(dishDTO);

        return Result.success();
    }

    /**
     * 修改菜品状态
     * @return
     */
    @ApiOperation("修改菜品状态")
    @PostMapping("/status/{status}")
    public Result updateDishStatus(@PathVariable Integer status, @RequestParam Long id){
        log.info("参数为:{}",id );
        dishService.updateDishStatus(status,id);

        return Result.success();
    }

}
